package br.inf.ufrgs.usixml4desktop.document;

import java.io.File;
import java.io.IOException;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.input.SAXBuilder;

public class UsiXMLDocument {
	
	private final String uiModelIdentifier = "uiModel";
	private final String cuiModelIdentifier = "cuiModel";
	private final String auiModelIdentifier = "auiModel";
	private final String contextModelIdentifier = "contextModel";
	private final String resourceModelIdentifier = "resourceModel";
	
	private Element rootElement = null;
	
	private Element auiModelElement = null;
	private Element cuiModelElement = null;
	private Element contextModelElement = null;
	private Element resourceModelElement = null;
	
	
	/**
	 * Loads a UsiXML file and separates its main parts.
	 * 
	 * @param file
	 * @throws IOException 
	 * @throws JDOMException 
	 */
	public UsiXMLDocument(File file) throws JDOMException, IOException {
		final boolean validate = false;
		
		SAXBuilder builder = new SAXBuilder(validate);
		Document doc = builder.build(file);
		
		this.rootElement = doc.getRootElement();
		Namespace usiXMLNamespace = this.rootElement.getNamespace();
		
		this.auiModelElement = this.rootElement.getChild(this.auiModelIdentifier,usiXMLNamespace);
		this.cuiModelElement = this.rootElement.getChild(this.cuiModelIdentifier,usiXMLNamespace);
		this.contextModelElement = this.rootElement.getChild(this.contextModelIdentifier,usiXMLNamespace);
		this.resourceModelElement = this.rootElement.getChild(this.resourceModelIdentifier,usiXMLNamespace);
	}


	public Element getAuiModelElement() {
		return auiModelElement;
	}


	public Element getContextModelElement() {
		return contextModelElement;
	}


	public Element getCuiModelElement() {
		return cuiModelElement;
	}


	public Element getResourceModelElement() {
		return resourceModelElement;
	}
	
	public String getStringResourceContent(Element element){
		return null;
	}
	
	

}
